import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserStore = defineStore(
  "user",
  () => {
    const user = ref("");
    const token = ref("");
    // 添加用户名
    const setUser = (u) => {
      user.value = u;
    };
    // 清除用户
    const removeUser = () => {
      user.value = "";
    };
    // 添加token
    const setToken = (t) => {
      token.value = t;
    };
    // 移除token
    const removeToken = () => {
      token.value = "";
    };
    return {
      user,
      token,
      setUser,
      removeUser,
      setToken,
      removeToken,
    };
  },
  {
    persist: {
      enabled: true,
      pick: ["user", "token"],
    },
  },
);
